function bincont = binread(filename)
% binread  - reads a binary into one uint8 array
%
% FORMAT:       bincont = binread(filename)
%
% Input fields:
%
%       filename    name to a file, preferably absolute path
%
% Output fields:
%
%       bincont     1xN uint8 array
%
% See also asciiread, binwrite

% Version:  v0.8a
% Build:    9102220
% Date:     Oct-22 2009, 2:56 PM CEST
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% enough arguments ?
if nargin < 1 || ...
   ~ischar(filename) || ...
    isempty(filename)
    error( ...
        'BVQXtools:BadArgument',...
        'Bad or missing argument.' ...
    );
end

% file exist check
filename = filename(:)';
if exist(filename, 'file') ~= 2
    error( ...
        'BVQXtools:FileNotFound',...
        'File not found: %s',...
        filename(1:min(length(filename), 80)) ...
    );
end

% open file check
fp = fopen(filename, 'r');
if fp < 1
    error( ...
        'BVQXtools:FileNotReadable',...
        'File not readable: %s',...
        filename ...
    );
end

% read file contents
bincont = fread(fp, [1, Inf], '*uint8');
fclose(fp);
